import axios from 'axios';
import store from '@/store/index'


// 创建axios实例
const service = axios.create({
    // bytetapper
    baseURL: "https://www.bytetapper.com/shop_api",
    timeout: 12000,
});

// 请求拦截
service.interceptors.request.use((config) => {

    config.headers['Content-Type'] = "application/json";
    config.headers['Authorization'] = `bearer ${store.state.userInfo.access_token}`;

    if (store.state.session_id) {
        config.headers['Bksessionid'] = store.state.session_id;
    }

    return config;

}, (error) => {
    // 请求错误
    return Promise.reject(error);
})

// 相应拦截 
service.interceptors.response.use((response) => {
    // const res = response.data;
    return response.data;

}, (error) => {
    // 响应错误
    return Promise.reject(error);
})

export default service;